package com.beaven.model.model.db;

import com.beaven.model.model.base.Author;
import com.beaven.model.utils.DataUtil;
import com.raizlabs.android.dbflow.annotation.Column;
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
import com.raizlabs.android.dbflow.annotation.Table;
import java.util.Date;

/**
 * author: Beaven
 * time: 2017/5/18 11:54
 */
@Table(database = AppDatabase.class) public class User extends BaseDbModel<User> implements Author {

  // 主键
  @PrimaryKey private String id;

  // 名称
  @Column private String name;

  // 头像
  @Column private String account;

  // 我对某人的备注信息
  @Column private String alias;

  // 好友列表
  @Column private int follows;

  @Column private int following;

  @Column private int categories;

  @Column private String categoryId;

  @Column private boolean isOnline;

  @Column private int chatColor;

  // 我与当前User的关系状态，是否已经关注了这个人
  @Column private boolean isFollow;

  // 时间字段
  @Column private Date modifyAt;

  @Override public String getId() {
    return id;
  }

  @Override public void setId(String id) {
    this.id = id;
  }

  @Override public String getName() {
    return name;
  }

  @Override public void setName(String name) {
    this.name = name;
  }

  public String getAlias() {
    return alias;
  }

  public void setAlias(String alias) {
    this.alias = alias;
  }

  public int getFollows() {
    return follows;
  }

  public void setFollows(int follows) {
    this.follows = follows;
  }

  public int getChatColor() {
    return chatColor;
  }

  public void setChatColor(int chatColor) {
    this.chatColor = chatColor;
  }

  public int getFollowing() {
    return following;
  }

  public void setFollowing(int following) {
    this.following = following;
  }

  public int getCategories() {
    return categories;
  }

  public void setCategories(int categories) {
    this.categories = categories;
  }

  public boolean isFollow() {
    return isFollow;
  }

  public void setFollow(boolean follow) {
    isFollow = follow;
  }

  public Date getModifyAt() {
    return modifyAt;
  }

  public void setModifyAt(Date modifyAt) {
    this.modifyAt = modifyAt;
  }

  public String getCategoryId() {
    return categoryId;
  }

  public String getAccount() {
    return account;
  }

  public void setAccount(String account) {
    this.account = account;
  }

  public void setCategoryId(String categoryId) {
    this.categoryId = categoryId;
  }

  public boolean isOnline() {
    return isOnline;
  }

  public void setOnline(boolean online) {
    isOnline = online;
  }

  @Override public boolean equals(Object obj) {
    if (this == obj) return true;
    if (obj == null || obj.getClass() != this.getClass()) return false;
    User user = (User) obj;
    return follows == user.follows
        && following == user.following
        && isFollow == user.isFollow
        && DataUtil.equals(id, user.id)
        && DataUtil.equals(name, user.name)
        && DataUtil.equals(alias, user.alias)
        && DataUtil.equals(categories, user.categories)
        && DataUtil.equals(categoryId, user.categoryId)
        && DataUtil.equals(modifyAt, user.modifyAt);
  }

  @Override public int hashCode() {
    return id != null ? id.hashCode() : 0;
  }

  @Override public boolean isSame(User old) {
    return this == old || DataUtil.equals(id, old.id);
  }

  @Override public boolean isUiContentSame(User old) {
    return this == old || (DataUtil.equals(name, old.name) && DataUtil.equals(isFollow,
        old.isFollow));
  }
}
